package com.master.train.business.controller;

import com.master.train.business.entity.TrainSeatEntity;
import com.master.train.business.service.TrainSeatService;
import com.master.train.common.utils.PageUtils;
import com.master.train.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;




/**
 * 座位
 *
 * @author master
 * @email 3221057417@qq.com
 * @date 2025-07-17 11:38:36
 */
@RestController
@RequestMapping("business/admin/train-seat")
public class TrainSeatController {
    @Autowired
    private TrainSeatService trainSeatService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = trainSeatService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		TrainSeatEntity trainSeat = trainSeatService.getById(id);

        return R.ok().put("trainSeat", trainSeat);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TrainSeatEntity trainSeat){
        Date now = new Date();
        if (trainSeat.getId() == null){
            trainSeat.setCreateTime(now);
            trainSeat.setUpdateTime(now);
        }else {
            trainSeat.setUpdateTime(now);
        }
		trainSeatService.saveOrUpdate(trainSeat);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TrainSeatEntity trainSeat){
		trainSeatService.updateById(trainSeat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		trainSeatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
